﻿/*
 * 打印报告绘图,血糖的报告
 * */
using System;
using System.Collections.Generic;
using System.Text;
using WH.NurseSys.Model;
using System.Drawing;

namespace WH.NurseSys.BLL.Report
{
    public class DrawReportGlucose:DrawReport
    {
        //绘制整个报告
        public void DrawReport(Graphics dc,Patient patient, List<Glucose> glucoseList, string reportTitle,float hardMarginX,float hardMarginY)
        {
            dc.PageUnit = GraphicsUnit.Document;
            dc.TranslateTransform(hardMarginX*3, hardMarginY*3);
            dc.Clear(Color.White);
            drawInfo(dc, patient, reportTitle);
            drawData(dc, glucoseList);
        }

        //绘制血糖测量数据
        private void drawData(Graphics dc, List<Glucose> glucoseList)
        {
            float x11 = 15 * dotPerMm;
            float x12=(15+30)*dotPerMm;
            float x13=(15+45)*dotPerMm;
            float x21 = (15 + 90) * dotPerMm;
            float x22 = (15 + 120) * dotPerMm;
            float x23 = (15 * 135) * dotPerMm;
            float yTop = (15 + 28) * dotPerMm;
            float yBottom = (297 - 15) * dotPerMm;            
            Font textFont = new Font("宋体", 14, FontStyle.Regular, GraphicsUnit.Point);
            dc.DrawString("血糖", textFont, Brushes.Black, x11, yTop);
            dc.DrawString("环境", textFont, Brushes.Black, x12, yTop);
            dc.DrawString("时间", textFont, Brushes.Black, x13, yTop);
            dc.DrawString("血糖", textFont, Brushes.Black, x21, yTop);
            dc.DrawString("环境", textFont, Brushes.Black, x22, yTop);
            dc.DrawString("时间", textFont, Brushes.Black, x23, yTop);
            dc.DrawLine(Pens.Black, (15 + 90) * dotPerMm, yTop, (15 + 90) * dotPerMm, yBottom);
            int columnCount = (int)(((297 - 15) * dotPerMm - yTop) / textFont.GetHeight(dc));
            float yCurrent = yTop+textFont.GetHeight(dc);
            for (int i = 0; i < glucoseList.Count; i++)
            {
                string measureContext=string.Empty;
                if (glucoseList[i].MeasureContext == 1)
                    measureContext = "空腹";
                else if (glucoseList[i].MeasureContext == 2)
                    measureContext = "餐前";
                else if(glucoseList[i].MeasureContext==3)
                    measureContext="餐后";
                if (i <= columnCount)
                {
                    dc.DrawString(glucoseList[i].Value.ToString(), textFont, Brushes.Black, x11, yCurrent);
                    dc.DrawString(measureContext, textFont, Brushes.Black, x12, yCurrent);
                    dc.DrawString(glucoseList[i].ExecTime.ToString("yy-MM-dd HH:mm"), textFont, Brushes.Black, x13, yCurrent);
                    if(i==columnCount)
                        yCurrent = yTop + textFont.GetHeight(dc);
                    else
                        yCurrent += textFont.GetHeight(dc);
                    
                }
                else
                {
                    dc.DrawString(glucoseList[i].Value.ToString(), textFont, Brushes.Black, x21, yCurrent);
                    dc.DrawString(measureContext, textFont, Brushes.Black, x22, yCurrent);
                    dc.DrawString(glucoseList[i].ExecTime.ToString("yy-MM-dd HH:mm"), textFont, Brushes.Black, x23, yCurrent);
                  
                        yCurrent += textFont.GetHeight(dc);
                }
            }
            textFont.Dispose();
        }
    }
}
